<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目属性</label>
                        <div class="layui-input-block radio-block">
                            <input type="radio" class="business1" name="business" value="1" title="自营" disabled>
                            <input type="radio" class="business2" name="business" value="2" title="联营" disabled>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目类型</label>
                        <div class="layui-input-block">
                            <div id="engintype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="lian_unitDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>联营方</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="lian_unit" class="layui-input lian_unit" onclick="openPage('../public/choose_dealcom.php?dom=lian_unit','80%','80%')">
                            <div class="choose_div" id="lian_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=lian_unit','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">建设单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="jian_unit" class="layui-input jian_unit" onclick="openPage('../public/choose_dealcom.php?dom=jian_unit','80%','80%')">
                            <div class="choose_div" id="jian_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=jian_unit','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>所属单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=chanid&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="chanid"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=chanid&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="chanid_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">所在地</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程造价(万元)</label>
                        <div class="layui-input-block">
                            <input type="number" name="expectfee" id="expectfee" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工期(天)</label>
                        <div class="layui-input-block">
                            <input type="text" name="duration" id="duration" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计划开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="startdt" id="startdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计划竣工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="enddt" id="enddt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">招标方式</label>
                        <div class="layui-input-block">
                            <div id="zhaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目负责人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=man_xiang&type=user&single=1', '770px', '490px');"></div>
                                <div class="tanxiannei" id="man_xiang"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=man_xiang&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="man_xiang_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>

                </div>
            </div>


            <div class="layui-form-item layui-hide" id="actualdtDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>实际开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="actualdt" id="actualdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="filishdtDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>竣工验收日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="filishdt" id="filishdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
                <div class="layui-form-item layui-hide" id="nexterDiv">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                            <div class="layui-input-block relative">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                    <div class="tanxiannei" id="nexter"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            </div>
                        </div>
                    </div>
                </div>
            <?php include '../public/upinfo.php'?>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    var param_isturn = getQueryVariable('isturn') || 0;
    if(param_isturn > 0){
        $("#billzhan").remove();
        $("#billtutn").remove();
        $("#billsub").attr('isshen', 1);
    }
    var param_billyushen = getQueryVariable('billyushen') || 0;
    if(param_billyushen == 2){
        $("#billyushen").addClass('layui-hide');
    }

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            actualdt: {required: true},
            filishdt: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            actualdt: {required: "请选择"},
            filishdt: {required: "请选择"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_edit_engin,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                    if(data.advaners_info.length > 0){
                        tan_tags_init('#advaners', data.advaners_info);
                    }
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                    if(data.nexter_info.length > 0){
                        tan_tags_init('#nexter', data.nexter_info);
                    }
                }
                if(data.flowrelas_info.length > 0){
                    set_choose_btn_more('flowrelas',data.flowrelas_info);
                }


                $("#name").val(data.name);
                $("#number").val(data.number);
                set_choose_btn('jian_unit',data.jian_unit,data.jian_unit);
                $("#addr").val(data.addr);
                $("#expectfee").val(data.expectfee);
                $("#duration").val(data.duration);
                $("#startdt").val(data.startdt);
                $("#enddt").val(data.enddt);
                $("#proer").val(data.proer);
                $("#actualdt").val(data.actualdt);
                $("#filishdt").val(data.filishdt);
                $("#explain").val(data.explain);

                if(data.business < 2){
                    $(".business1").prop('checked', true);
                }else{
                    $(".business2").prop('checked', true);
                    $("#lian_unitDiv").removeClass('layui-hide');
                    set_choose_btn('lian_unit',data.lian_unit,data.lian_unit);
                }

                if(data.chanid_info.length > 0){
                    tan_tags_init('#chanid', data.chanid_info);
                }

                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(data.state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else{
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }
                }
                $("#state").html(state_str);

                if(data.state == 3){
                    $("#actualdtDiv").removeClass('layui-hide');
                }else if(data.state == 6){
                    $("#actualdtDiv").removeClass('layui-hide');
                    $("#filishdtDiv").removeClass('layui-hide');
                }


                if(data.man_xiang_info.length > 0){
                    tan_tags_init('#man_xiang', data.man_xiang_info);
                }

                $("#areas").val(data.areas);
                load_areas('areas', res.data.areas, 3);
                xmselect_dan('engintype', res.data.engintype, data.engintype);
                xmselect_dan('zhaotype', res.data.zhaotype, data.zhaotype);


                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }

            if(data.value == 3){
                $("#actualdtDiv").removeClass('layui-hide');
                $("#filishdtDiv").addClass('layui-hide');
            }else if(data.value == 6){
                $("#actualdtDiv").removeClass('layui-hide');
                $("#filishdtDiv").removeClass('layui-hide');
            }else{
                $("#actualdtDiv").addClass('layui-hide');
                $("#filishdtDiv").addClass('layui-hide');
            }

        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.isshen = $(this).attr('isshen') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');

            data.field.jian_unit = get_choose_val('jian_unit');
            data.field.lian_unit = get_choose_val('lian_unit');
            data.field.chanid = tan_tags_getvalue("#chanid", 'dept');
            data.field.man_xiang = tan_tags_getvalue("#man_xiang", 'user');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                if(data.field.business == 2){
                    data.field.lian_unit = get_choose_val('lian_unit');
                    formValid('lian_unit');
                    if(data.field.lian_unit == undefined || !data.field.lian_unit){
                        validRes = false;
                    }
                }

                data.field.chanid = tan_tags_getvalue("#chanid", 'dept');
                if(!data.field.chanid){
                    $("#chanid").parents('.tanxian').addClass('tanerror');
                    $('#chanid_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#chanid").parents('.tanxian').removeClass('tanerror');
                    $('#chanid_tanerror').text('');
                }

                if(data.field.state == ''){
                    $('#state_error').show().text('请选择');
                    $('#state_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#state_error').hide();
                    $('#state_error').parent().find('input').removeClass('select_error');
                }


                if(!data.field.man_xiang){
                    $("#man_xiang").parents('.tanxian').addClass('tanerror');
                    $('#man_xiang_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#man_xiang").parents('.tanxian').removeClass('tanerror');
                    $('#man_xiang_tanerror').text('');
                }
                if(!validRes){return false;}
            }

            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');

            public_flow_submit(data.field, ask_flowdata_add_engin, ask_flowdata_edit_engin, $(this).attr('but'));
            return false;
        });

    });


</script>
</body>
</html>
